Skip to content

fix: medium- and low-severity parser and formatter bugs found by property tests - #13

Merged
raydive merged 24 commits into
masterfrom
fix/medium-low-severity-bugs
Dec 4, 2026
Merged

raydive merged 24 commits into
masterfrom
fix/medium-low-severity-bugs

Conversation

@raydive

@raydive raydive commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

概要

プロパティテスト(ephyra)で見つかった不具合のうち、#12 で扱わなかった中・低重大度のものを修正します。パーサーの扱いが CommonMark と違う件、深い入れ子や閉じない括弧で処理が重くなる・スタックオーバーフローする件、Formatter が出力の意味を変えてしまう件が中心です。修正ごとにテストを追加し、各モジュールのテストスイートに登録しています。

修正内容

パーサー・HTML 出力

番号 不具合 修正 コミット
vsch#14 CR だけの改行で、コードブロックの空行や HTML ブロック末尾の改行が消える。タイトル・alt・未定義参照では次の行の字下げが残る Escaping.normalizeEOL で単独の CR を改行として扱う。タイトル、alt、未定義参照の文字列も改行を正規化する 922e991, 2f0979e
#5 - や > を数百段入れ子にすると、描画・Formatter・Visitor がスタックオーバーフローする Parser.BLOCK_NESTING_LIMIT を追加(既定 100、0 以下で無効)。上限を超えるコンテナは開かず、段落のテキストとして残す 2913ee3
vsch#6 [x](a(b ) がリンクになり、[r]: a(b が参照定義として消える 括弧が閉じていないリンク先を受け付けない(CommonMark 0.29 6.5)。Jekyll マクロモードは既存テストに合わせて従来どおり 24f9af6
#4 [a]( の繰り返しで処理時間が入力長の 2 乗になる(64 KB で約 0.6 秒) リンク先の括弧の入れ子を 32 段までに制限する(仕様で許されている)。64 KB で 11〜20 ms になる 6cb4f41
vsch#18 未定義参照の中の強調が、段落の位置によって結果が変わる(*[*] と a\n\n*[*]) Bracket.isStraddling で段落内の位置と文書内の位置を比べていた。文書内の位置に揃える 53b3e6d
vsch#27 ![[x]]() の alt が x になる(CommonMark では [x]) 未定義参照の前後の括弧も alt に含める。見出しの id は既存のアンカーを変えないよう従来どおり 5ccd2f3
vsch#22 項のない定義項目が <dl> のない <dd> になる 項がない場合は段落として扱う(拡張のスペックと同じ) 62c0cbf

Formatter

番号 不具合 修正 コミット
#11 山括弧の画像リンク先で < が整形のたびに増える(![](<a>) → ![](<<a>)) < を 2 回書いていたので 1 回にする 1bdf195
#10 参照定義で終わる引用が、次の引用とつながる 末尾の空行を tailBlankLine() で書き、引用の終わりでは > を付けない fbd0f47
#7 空の定義項目で NullPointerException、引用内の定義項目で StringIndexOutOfBoundsException マーカーをノードから取り、空の項目と引用で始まる項目を正しく書く 36ee7e0
#13 閉じていない HTML ブロックに整形のたびに空行が増え、引用内では次の引用とつながる pre-formatted モードを先に閉じる。終了条件を満たさない HTML ブロックの後には空行を足さない f70a412
vsch#25 > だけの引用が消え、> > の内側の引用が消える 子のない引用でもマーカーの行を書く 9ab3b57
#9 リスト項目の先頭の見出し・区切り線・フェンス・HTML ブロック・脚注定義が、項目の外に出る(- # a → 空のリストと見出し) FormatterUtils.blankLineBeforeBlock と tailBlankLineAfterBlock を追加し、項目の最初のブロックの前に空行を入れない。タイトなリストがルーズにならないようにする 1a08541
vsch#21 引用内で、次の行に書いたリンク先やタイトルが参照定義として読めない 参照定義を段落の content lines から読む 7939a1b
#8, vsch#23 字下げした継続行や遅延継続行が、整形後にリスト・見出し・setext 下線として読まれる 次の行がブロックを始める書き方なら、4 桁字下げして段落の継続にしかならないようにする 7705eac
#12 リンクテキストの括弧内の空白が消える([\t][o] が [o] への参照になる) 括弧とテキストの間の空白を元のとおり書く 04a0dcb
vsch#24 参照ラベルの括弧内の空白が消え、[\ ] が [\] になる ラベルの両側の空白を元のとおり書く a92ce4a

挙動が変わる点

  • 新しいオプション Parser.BLOCK_NESTING_LIMIT(既定 100)を追加しました。ブロックコンテナが 100 段を超える入れ子は、それ以上開かずに段落のテキストになります。
  • 括弧が閉じていないリンク先([x](a(b ) など)はリンクになりません。括弧の入れ子が 33 段以上のリンク先もリンクになりません。
  • 画像の alt に、未定義参照の括弧が含まれるようになりました。
  • Formatter の出力が変わる箇所があります(リスト項目の先頭ブロック、継続行の字下げ、括弧内の空白、空の引用など)。どれも、整形前と整形後で HTML が同じになる方向の変更です。
  • flexmark-integration-test の pom.xml に、テスト用の依存(flexmark-ext-definition)を追加しました。

未修正のもの

テスト

  • mvn -o test -pl '!flexmark-osgi':9,418 件すべて通過しました。スキップは 145 件です(flexmark-osgi はオフラインでプラグインを取得できないため除外)。
  • ephyra の回帰テスト 37 件のうち 35 件が通過しました。残り 2 件は上記の未修正のもの(HtmlBlock and newline vsch/flexmark-java#26 とフェンスの末尾改行)です。
  • 利用側のアプリケーションの 12 プロジェクトで、現行の flexmark とこのブランチのテスト結果を比べ、すべて一致し失敗は 0 件でした(Markdown 描画のテスト 1,511 件を含む)。

Generated with Claude Code

raydive and others added 18 commits December 4, 2026 08:32
Escaping.normalizeEOL turned "\r\r" into a single "\n" and dropped a
trailing "\r", so blank lines vanished from fenced and indented code and
HTML blocks lost their last line ending when the document used lone CR
line endings (CommonMark 0.29 section 2.1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ferences

The HTML writer only sees "\n" as a line end, so after a lone "\r" the
indent of the next line was kept in link and image titles, image alt
text and the literal text of an undefined reference, and "\r\n" was
written out as is. Normalize these strings like Text nodes already are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Parser.BLOCK_NESTING_LIMIT (default 100, <= 0 disables). DocumentParser
skips a block start that would open a container deeper than the limit, so
the text stays in the deepest allowed container as paragraph text. The
renderers, Formatter and visitors recurse per nesting level and overflowed
a 1 MiB stack at a few hundred nested "- " or "> ".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CommonMark 0.29 6.5 allows parentheses in a non-angled link destination
only when they are escaped or balanced. LinkDestinationParser counted an
opening parenthesis but never checked the count at the end, so
`[x](a(b )` rendered as a link and `[r]: a(b` was swallowed as a
reference definition.

The parser now returns null when parentheses remain open, and
InlineParserImpl treats that as no destination. Jekyll macro mode keeps
its old behavior because LinkDestinationParserTest encodes unbalanced
results for it (test_Jekyll16, 18, 20, 21).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
render(Image) appended the URL opening marker before choosing between
translation spans and the other render purposes, and the non-translation
branch appended it again. An image destination in angle brackets gained
one "<" per pass: "![](<a>)" became "![](<<a>)", which renders as a link
to "<a" ("&lt;a"), and "![](<>)" became "![](<<>)". Drop the second append,
as render(Link) does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…offset

Bracket.isStraddling compared paragraph-relative delimiter indices with
document offsets, so the check only worked for a paragraph starting at
offset 0. "a\n\n*[*]" rendered "<p>*[*]</p>" while "*[*]" rendered
"<em>[</em>]". Map the delimiter to document offsets before comparing.

Delimiters that pair with each other inside the brackets, such as the
translation placeholder in "**x [_3_] y**", no longer count as
straddling, so the reference is kept at every offset as the translation
formatter needs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every `](` started a destination scan that ran to the end of the input
when the parentheses never closed, so `[a](` repeated (also `[a](<`,
`![a](`, `[](`) parsed in quadratic time: 64 KB took about 0.6 s.

CommonMark 0.29 6.5 lets implementations limit parenthesis nesting (at
least 3 levels). LinkDestinationParser now rejects a destination with
more than 32 nested unescaped parentheses, which bounds each scan and
makes these inputs linear (64 KB now 11-20 ms).

Output changes only for destinations nested deeper than 32 levels:
`[l](` + 33 x `(` + `a` + 33 x `)` + `)` used to render as a link and
now stays literal text. 32 levels still render as a link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A reference definition rendered AS_IS ended with blankLine(), which writes
the blank line with the current prefix. When the definition was the last
block of a block quote, that blank line became a ">" line, which the next
block quote then continued: ">- [r]: a\n\n>- b" was formatted as one block
quote "> - [r]: a\n>\n> - b". Use tailBlankLine(), which drops the block
quote marker when the node ends the block quote and keeps it otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DefinitionNodeFormatter took the marker from the chars before the first
child, so an empty item threw a NullPointerException and an item in a
block quote, whose child starts before the marker, threw a
StringIndexOutOfBoundsException. Take the marker from the node, end the
marker line of an empty item while the enclosing prefixes apply, and put
a block quote first child on the marker line like a list item does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An HTML block was written in pre-formatted mode with line() before
closePreFormatted(). In pre-formatted mode line() always ends a line, so
a block whose last content line already ended with EOL got an extra
empty line, written with the current prefix. At the end of the document
"<style" grew by one blank line per pass, and in a block quote the extra
">" line joined the next block quote: "> <div>\n\n> b" became one block
quote. Close pre-formatted mode first, as for HTML comment blocks.

An HTML block of type 1, 3, 4 or 5 whose end condition never matched
runs to the end of its container and takes a blank line after it as its
content, so "<style" rendered as "<style\n\n". When formatting, do not
add the tail blank line after such a block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RefNode.collectText collected only the children of an undefined
reference, so "![[x]]()" gave alt="x" where CommonMark gives "[x]".
Collect the literal prefix and suffix around the children, as the HTML
renderer does for undefined references. Heading ids keep the old text
so existing anchors do not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
renderBlockQuoteLike wrote the ">" marker only as the prefix of the lines
its children wrote. A block quote with no children, or only blank lines,
wrote no line, so ">" was formatted as an empty document and "> >" lost
the inner block quote. Write the marker on a line of its own for such a
block quote, followed by the usual tail blank line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A definition item may start after a paragraph that later turns out to
hold only reference definitions ("[F]:_\n: &"), or inside an empty
item. With no paragraph left to split into terms, the item stayed as a
<dd> without a <dl>. The extension's spec renders a marker line with no
term as a paragraph, so make the item a paragraph that starts at its
marker, which matches the HTML of the same text without the extension.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The formatter writes the list item marker and then renders the item's
first block on the same line. Headings, thematic breaks, fenced code,
HTML blocks and footnote definitions start with blankLine(), which ended
the marker line and left a blank line, so the item ended empty and the
block followed the list: "- # a" became "- \n\n  # a" (a heading after an
empty list) and "3) <u>" an HTML block after the list. Only
renderBlockQuoteLike honoured FIRST_LIST_ITEM_CHILD.

Add FormatterUtils.blankLineBeforeBlock, which skips the blank line for
the first block of a list item while FIRST_LIST_ITEM_CHILD is set, and
use it in those formatters. The flag stays set for descendants of the
first block, so the helper also checks that the node is the item's first
child.

With the block kept in the item, its tail blank line now separated two
items of a tight list and made it loose: "- # a\n- b". Add
FormatterUtils.tailBlankLineAfterBlock, which ends the last block of an
item without a blank line unless the list is loose (or LIST_ITEM_SPACING
is LOOSE), and use it for headings, thematic breaks and HTML blocks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
preProcessBlock parsed the paragraph's chars, which span the source and
so still hold the prefixes of continuation lines. In a block quote a
destination on the next line became ">/url", "> [a]:\n> /url" was not
a definition, and a title on the next line was lost. Parse the content
lines instead, as inline parsing does; offsets still map to the source.
The Reference node's chars span those content lines too, so the
Formatter does not write the block quote markers twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without a right margin the formatter writes the lines of a paragraph as
they are, each at the indent of its container. A continuation line that
was indented by 4 or more columns, or was a lazy continuation line, then
moved to the container's indent, where block syntax on it starts a new
block: "a\n    - b" became a list, "]\n    -" a setext heading, and the
lazy line in "- _\n=" (which cannot underline a setext heading) was
indented into the list item and underlined one.

After a soft or hard line break, when the source text of the next line
starts a block that can interrupt a paragraph (list item, ATX heading,
block quote, fence, thematic break, HTML block types 1 to 6) or is a
setext heading underline, write it indented by 4 columns, where it can
only continue the paragraph. Other continuation lines are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The parser trims the whitespace inside the brackets from the text of a
link, link reference and image reference, and the formatter wrote only
the trimmed text. The whitespace is part of the source: "[\t][o]" is not
a reference to "o" while "[][o]" is, and "[]([ \]](> ''))" became
"[]([\]](> ''))", where "\]" turns the text into a link.

Write the whitespace between the opening bracket and the text, and
between the text and the closing bracket, as in the source. Whitespace
with a line break is left out, since the soft line breaks of the text
write the line break.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The formatter wrote the whitespace between the opening bracket and the
label of a link reference, but not between the label and the closing
bracket, and wrote none for image references. "[- ]" became "[-]",
"![- ]" became "![-]", and "[\ ]" became "[\]", an escaped bracket:
"[a][\ ]" then rendered as "[a][]".

Write the whitespace on both sides of the label of link and image
references, as for the link text. The branches used when wrapping to a
right margin are left as they are: core_wrapping_spec.md example
"Wrap - Restore Spaces: 55" expects "[B ]" to be formatted as "[B]".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Before Java 20, Matcher.toMatchResult() copies the whole input, so every
match() and matchWithGroups() call was linear in the input length. spnl()
runs at every "](", which kept unclosed link destinations quadratic on
Java 11 and timed out the pathological tests on CI. Read the offsets
from the matcher directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Formatting can trigger a StackOverflowError on valid input, and unresolved findings identify quadratic scanning and parsing and round-trip correctness regressions.

6 open issues
What changed in this PR

This PR addresses parser, HTML rendering, and formatter bugs found by property tests, following the higher-severity fixes in #12.

Changes:

  • Bounds block and link-destination nesting and corrects reference parsing.
  • Preserves line endings, image alt text, and document meaning during formatting.
  • Adds regression tests across core, definition, footnote, and integration modules.
File Description
flexmark/​src/​main/​java/​com/​vladsch/​flexmark/​parser/​Parser.java Adds configurable block nesting limit.
flexmark/​src/​main/​java/​com/​vladsch/​flexmark/​parser/​internal/​LinkDestinationParser.java Rejects unbalanced and excessive parentheses.
flexmark/​src/​main/​java/​com/​vladsch/​flexmark/​parser/​internal/​InlineParserImpl.java Parses references from container-stripped content.
flexmark/​src/​main/​java/​com/​vladsch/​flexmark/​parser/​internal/​DocumentParser.java Enforces block nesting limits.
flexmark/​src/​main/​java/​com/​vladsch/​flexmark/​parser/​core/​delimiter/​Bracket.java Revises delimiter boundary checks.
flexmark/​src/​main/​java/​com/​vladsch/​flexmark/​html/​renderer/​CoreNodeRenderer.java Normalizes rendered line endings.
flexmark/​src/​main/​java/​com/​vladsch/​flexmark/​formatter/​NodeRepositoryFormatter.java Preserves separation after references.
flexmark/​src/​main/​java/​com/​vladsch/​flexmark/​formatter/​internal/​CoreNodeFormatter.java Preserves block structure and link whitespace.
flexmark/​src/​main/​java/​com/​vladsch/​flexmark/​formatter/​FormatterUtils.java Adjusts list spacing and empty quotes.
flexmark/​src/​main/​java/​com/​vladsch/​flexmark/​ast/​RefNode.java Keeps undefined-reference brackets in collected text.
flexmark-util-sequence/​src/​main/​java/​com/​vladsch/​flexmark/​util/​sequence/​Escaping.java Preserves standalone CR line endings.
flexmark-integration-test/​src/​test/​java/​com/​vladsch/​flexmark/​integration/​test/​NestedContainerStackOverflowTest.java Tests deeply nested container pipelines.
flexmark-integration-test/​src/​test/​java/​com/​vladsch/​flexmark/​integration/​test/​IntegrationTestSuite.java Registers nesting regression tests.
flexmark-integration-test/​pom.xml Adds definition-extension test dependency.
flexmark-ext-footnotes/​src/​test/​java/​com/​vladsch/​flexmark/​ext/​footnotes/​FootnoteInListItemFormatterTest.java Tests footnote formatting inside lists.
flexmark-ext-footnotes/​src/​test/​java/​com/​vladsch/​flexmark/​ext/​footnotes/​ExtFootnotesTestSuite.java Registers footnote regression tests.
flexmark-ext-footnotes/​src/​main/​java/​com/​vladsch/​flexmark/​ext/​footnotes/​internal/​FootnoteNodeFormatter.java Avoids detaching first-child footnotes.
flexmark-ext-definition/​src/​test/​java/​com/​vladsch/​flexmark/​ext/​definition/​ExtDefinitionTestSuite.java Registers definition edge-case tests.
flexmark-ext-definition/​src/​test/​java/​com/​vladsch/​flexmark/​ext/​definition/​DefinitionEdgeCaseTest.java Tests empty and termless definitions.
flexmark-ext-definition/​src/​main/​java/​com/​vladsch/​flexmark/​ext/​definition/​internal/​DefinitionNodeFormatter.java Handles empty and quoted definition content.
flexmark-ext-definition/​src/​main/​java/​com/​vladsch/​flexmark/​ext/​definition/​internal/​DefinitionListItemBlockPreProcessor.java Converts termless definition items to paragraphs.
flexmark-core-test/​src/​test/​java/​com/​vladsch/​flexmark/​core/​test/​util/​parser/​UnbalancedLinkDestinationTest.java Tests rejection of unbalanced destinations.
flexmark-core-test/​src/​test/​java/​com/​vladsch/​flexmark/​core/​test/​util/​parser/​ReferenceInBlockQuoteTest.java Tests multiline quoted references.
flexmark-core-test/​src/​test/​java/​com/​vladsch/​flexmark/​core/​test/​util/​parser/​LinkDestinationParserTest.java Adds destination parser edge cases.
flexmark-core-test/​src/​test/​java/​com/​vladsch/​flexmark/​core/​test/​util/​parser/​LineEndingEquivalenceTest.java Checks equivalent rendering across line endings.
flexmark-core-test/​src/​test/​java/​com/​vladsch/​flexmark/​core/​test/​util/​parser/​EmphasisInUndefinedReferenceTest.java Tests position-independent emphasis handling.
flexmark-core-test/​src/​test/​java/​com/​vladsch/​flexmark/​core/​test/​util/​parser/​BlockNestingLimitTest.java Tests nesting limits and fallback behavior.
flexmark-core-test/​src/​test/​java/​com/​vladsch/​flexmark/​core/​test/​util/​html/​PathologicalRenderingTestCase.java Adds repeated unclosed-destination cases.
flexmark-core-test/​src/​test/​java/​com/​vladsch/​flexmark/​core/​test/​util/​html/​ImageAltUndefinedReferenceTest.java Tests literal reference text in image alt.
flexmark-core-test/​src/​test/​java/​com/​vladsch/​flexmark/​core/​test/​util/​formatter/​FormatterKeepsDocumentTest.java Tests formatting stability and HTML preservation.
flexmark-core-test/​src/​test/​java/​com/​vladsch/​flexmark/​core/​test/​util/​formatter/​CoreFormatterTestSuite.java Registers formatter regression tests.
flexmark-core-test/​src/​test/​java/​com/​vladsch/​flexmark/​core/​test/​util/​CoreTestSuite.java Registers parser and renderer regression tests.

Review effort: Balanced

raydive and others added 3 commits December 4, 2026 11:16
Check for a thematic break without a regex: the repeated group recursed
once per marker and overflowed the stack on a long line. Treat zero
padded ordered list markers such as "01." as starting with 1, as the
parser does. Find the content line after a line break by binary search,
instead of scanning the paragraph's lines from the start for every
break.

Count the nesting depth for Parser.BLOCK_NESTING_LIMIT from the parser
that will accept the started blocks: addChild() closes the matched
parsers that cannot contain them, so "- a\n+ b" starts a sibling list,
not a nested one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
isStraddling paired an opener with any closer of the same character in
the bracket region, so in "*x [**a*]b*" the "**" run paired with one "*"
although its other "*" can pair outside of the brackets. Pair only runs
of the same length and treat the region as straddled otherwise, as it
was before delimiters inside the region could pair.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SimTocBlockParser.canContain() records the child it accepts, so asking
it for every block start broke the simulated TOC. Count the depth from
the active parser chain first and walk up with canContain() only when
that depth would reject the block start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active findings identify quadratic delimiter processing and regressions in emphasis pairing, resolved-image alt text, and undefined-reference whitespace preservation.

1 open issue
3 previously missed issues

In code that hasn't changed since last review

Medium severity Preserve image alt text for custom-resolved references

flexmark/​src/​main/​java/​com/​vladsch/​flexmark/​ast/​RefNode.java:239

isDefined() is still false when an image reference is successfully resolved by a custom LinkResolver. CoreNodeRenderer.render(ImageRef) then collects text starting at that same node, so resolving ![photo] to /photo.png now produces alt="![photo]" instead of alt="photo". Please distinguish the resolved image being rendered from genuinely undefined references nested inside its description, so the new literal-bracket handling only applies to the latter.

Medium severity Preserve line breaks in directly emitted reference labels

flexmark/​src/​main/​java/​com/​vladsch/​flexmark/​formatter/​internal/​CoreNodeFormatter.java:1130

Reference labels are emitted directly from trimmed getReference() text, without SoftLineBreak children to restore omitted newlines. Skipping EOL-containing gaps changes the undefined reference [a][\n b] to [a][b], removing visible whitespace that the previous leading-whitespace call preserved. Preserve those gaps for directly emitted labels, and suppress them only when rendered children already supply the line breaks.

Medium severity Check delimiter rules before pairing equal-length runs

flexmark/​src/​main/​java/​com/​vladsch/​flexmark/​parser/​core/​delimiter/​Bracket.java:109

Equal-length runs can still fail to pair: in *x [a***b***c] y*, EmphasisDelimiterProcessor.getDelimiterUse() rejects the inner triple runs under its multiple-of-three rule. Treating them as paired creates a tentative reference and discards delimiters that should match across the brackets, changing the rendered emphasis. Consult the configured delimiter processor's matching rules before accepting an internal pair, and add this equal-length regression case.

6 resolved since last review

Review effort: Balanced

- Bracket.isStraddling keeps the unpaired openers in a stack per
  delimiter character, so finding and removing the last one is constant
  time, and pairs two runs only when the delimiter processor accepts
  them and the runs only open and only close, so the "multiple of 3"
  rule cannot keep them apart: "*x [a***b***c] y*" now renders as at
  offset 0 before the straddling change.
- A rendered image reference collects the alt text from its children,
  so an image reference that a link resolver resolves keeps "photo" as
  alt text instead of "![photo]".
- The whitespace inside the brackets of a reference label keeps its
  line breaks: the label is written from source text, with no soft line
  break nodes, so "[a][\n b]" no longer becomes "[a][b]".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@raydive
raydive requested a balanced review from Copilot December 4, 2026 05:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved defects mis-handle crossing emphasis pairs, leave image alt references stale after reference transfers, and duplicate list indentation, breaking formatter idempotence.

2 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Recheck transferred references when collecting image alt text

flexmark/​src/​main/​java/​com/​vladsch/​flexmark/​ast/​RefNode.java:238

isDefined() can remain false after references are transferred into the document. For example, parse ![[x]](), then transfer references from a document containing [x]: /u: this branch still produces alt="[x]" instead of alt="x". Image alt collection visits descendants directly, bypassing the renderer's undefined-reference recheck. Please recheck descendant references against the current document before treating their brackets as literal.

1 resolved since last review

Review effort: Balanced

- Treat crossing emphasis pairs inside brackets as straddling: the inner
  pair removes the openers between its runs, which moves the outer pair.
- Look up references in the document when collecting the text of an
  undefined reference, so references transferred after parsing count.
- Write only the line break of a reference label gap: the writer adds the
  container prefix, so copying it from the source doubled the indent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because unpublished findings identify formatting-induced parsing changes, nesting-limit violations, and incorrect multiline reference text.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@raydive
raydive merged commit 112ad21 into master Dec 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants